package cn.picclife.mwx.manager.sys.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.picclife.mwx.manager.sys.model.bo.DataResponse;
import cn.picclife.mwx.manager.sys.model.bo.ScreenShotBo;
import cn.picclife.mwx.manager.sys.service.IFileUploader;
import cn.picclife.mwx.manager.util.enums.ResponseStatusEnum;

@RestController
public class FileUploaderController {
	private Log log = LogFactory.getLog(FileUploaderController.class);
	@Autowired
	private IFileUploader fileService;
	
	/**
	 * 保存截屏图片到服务器
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/uploadFile2Repostry")
	public DataResponse uploadSignIdFile(HttpServletRequest request, HttpServletResponse response, @RequestBody ScreenShotBo shot){
		DataResponse dataresponse = new DataResponse();
		try {
			dataresponse = fileService.saveFile(shot);
		} catch (Exception e) {
			log.error(e);
			dataresponse.setCode(ResponseStatusEnum.EXCEPTION.getCode());
			dataresponse.setMsg(ResponseStatusEnum.EXCEPTION.getName() + "；" + e.getMessage());
		}
		return dataresponse;
	}
	
	
	/**
	 * 保存文件到服务器
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/uploadZip2Repostry")
	public DataResponse uploadFile2Repostry(HttpServletRequest request, HttpServletResponse response, @RequestParam("uploadFile") MultipartFile file){
		DataResponse msg = new DataResponse();
		try {
			msg = fileService.saveFile(file);
		} catch (Exception e) {
			log.error(e);
		}
		return msg;
	}
	
	
	/**
	 * 查询图片
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryFileByCollectId")
	public DataResponse queryFileByCollectId(HttpServletRequest request, HttpServletResponse response, @RequestBody ScreenShotBo shot){
		DataResponse dataresponse = new DataResponse();
		try {
			dataresponse = fileService.queryFileByCollectId(shot);
		} catch (Exception e) {
			log.error(e);
			dataresponse.setCode(ResponseStatusEnum.EXCEPTION.getCode());
			dataresponse.setMsg(ResponseStatusEnum.EXCEPTION.getName() + "；" + e.getMessage());
		}
		return dataresponse;
	}
}
